/*Prepared Using STATA 16: September 16, 2023*/
cap cd "C:\Users\ejm5\Dropbox\Vietnam Election project\2021_Election\Replication"
use "Final data - all phases v2.dta", clear

drop Questionnaire_order

*Merge with undergrad major dataset & questionnaire order
merge 1:1 assignedID using "Undergrad major recoded.dta" 
merge 1:1 assignedID using "Questionnaire_order.dta", generate(merge2) 

destring votingdivision,replace 
merge m:1 votingdivision using "ElectoralDistrictsV2.dta", generate(merge3)

*Recoding relevant variables to English
label var respid "Respondent ID"
drop university_id gender_rc 
encode university, gen (university_id)
label define university_id 1 "Bach Khoa University" 2 "University of Science" 3 "University of Social Sciences & Humanities" 4 "University of Economics HCMC" 5 "University of Architecture HCMC" 6 "Open University HCMC" 7 "Banking University HCMC" 8 "University of Pedagogy HCMC" 9 "University of Pharmacy HCMC",replace
label values university_id university_id
encode gender, gen (gender_rc)
label define gender_rc 1 "Male" 2 "Female",replace
label var gender_rc "Gender"


*Generate Political background variable
drop polibg polibg_yes polibg_no
destring famingov_none famingov_parents famingov_uncleaunt famingov_grandparents famingov_siblings famingov_cousins famingov_friends, replace
egen polibg_yes=rmax(famingov_parents famingov_uncleaunt famingov_grandparents famingov_siblings famingov_cousins famingov_friends)
gen polibg_no=0 if famingov_none==1
egen polibg=rowtotal(polibg_yes polibg_no)
label define polibg2 0 "No" 1 "Yes"
label val polibg polibg2
label var polibg "Has at least one family member/friend in VCP or VN government?"

*Generate Political status 
drop polistat polistat_yes polistat_no
destring selfingov_yu selfingov_vcp selfingov_none, replace
egen polistat_yes=rmax(selfingov_yu selfingov_vcp)
gen polistat_no=0 if selfingov_none==1
egen polistat=rowtotal(polistat_yes polistat_no)
label define polistat2 0 "No" 1 "Yes"
label val polistat polistat2
label var polistat "Self at least in one VN governmental organization/VCP?"

*Generate Political interest variable
drop politicsinterest_rc
encode politicsinterest, gen(politicsinterest_rc)
replace politicsinterest_rc=3 if politicsinterest_rc==4
label define politicsinterest_rc 1 "None" 2 "Not much" 3 "Some/A good deal",replace
label var politicsinterest_rc "Generally speaking, how much interest do you usually have in politics?"

*Generate Election Awareness variable
drop electiondateawareness_rc
encode electiondateawareness, gen(electiondateawareness_rc)
label define electiondateawareness_rc 1 "No" 2 "Yes",replace
label val electiondateawareness_rc electiondateawareness_rc
label var electiondateawareness_rc "Know what is the exact Election date?"

*This variable is used for connecting all datasets together*
label var assignedID "Assigned experiment ID" 


*Election_result - used to record when result was announced
label define Election_result 0 "Not yet" 1"Yes"
label var Election_result "Election result announcement"

*Questionnaire_order - used to record when questionnaire order was changed
label define Questionnaire_order 1"Q2 - Q4 only answered if vote in-person and behind Q12" 2 "Q2 - Q4 right after Q1"
label var Questionnaire_order "Questionnaire order"

*P3 - used to record if respondent has participated in Phase 3
label var P3 "Participated in Phase 3?"

*p2_physicaldelivery - used to record physical treatment in phase 2
label var p2_physicaldelivery "Received physical treatment in Phase 2"

*p2_Qrdelivery - used to record digital treatment in phase 2
label var p2_Qrdelivery "No. of times open QR code in Phase 2"

drop pic
drop Q8_recode Q9_recode
drop Q8Q9_recodeconfidence

*Q5
encode Q5, gen (Q5_en)
label define Q5_en 1"I did not vote in the last election" 2"I voted via another person in the last election" 3"I voted in-person in the last election",replace
label values Q5_en Q5_en
label var Q5_en "Please choose the statement that is most applicable to you in last May election"

*Q8
encode Q8, gen (Q8_en)
label define Q8_en 1 "Yes, I remember at least one name of the candidates I voted for" 2 "No, I remember none of the candidates' names",replace
label var Q8_en "Can you name one or more of the candidates you voted for in the last election?"
label var 	Q8b_name_NA_HCM	"	No. of names in HCM in NA	"
label var 	Q8b_name_PC_HCM	"	No. of names in HCM in PC	"
label var 	Q8b_name_NA_origin	"	No. of names in hometown in NA	"
label var 	Q8b_name_PC_origin	"	No. of names in hometown in PC	"
label var 	Q8b_name_NA_others	"	No. of names in other places in NA	"
label var 	Q8b_name_PC_others	"	No. of names in other places in PC	"

*Q9
encode Q9, gen (Q9_en)
label define Q9_en 1 "Yes, I remember at least one positions of the candidates I voted for" 2 "No, I remember none of the candidates' positions",replace
label var Q9_en "Can you name the positions of one or more of the candidates you voted for?"
label var 	Q9b_pos_NA_HCM	"	No. of positions in HCM in NA	"
label var 	Q9b_pos_PC_HCM	"	No. of positions in HCM in PC	"
label var 	Q9b_pos_NA_origin	"	No. of positions in hometown in NA	"
label var 	Q9b_pos_PC_origin	"	No. of positions in hometown in PC	"
label var 	Q9b_pos_NA_others	"	No. of positions in other places in NA	"
label var 	Q9b_pos_PC_others	"	No. of positions in other places in PC	"

*Q8Q9 - to mark case where our confidence in recoding is low
label define Q8Q9_recodeconfidence 0 "Confident" 2 "Not too confident",replace

*Q6 Q7 Q10 Q11 Q12
drop Q6 Q7 Q10 Q11 Q12
label var	Q7_1	"	I want to exercise my right of suffrage	"
label var	Q7_2	"	I want to contribute to my country	"
label var	Q7_3	"	I want my thoughts and interests to be represented in the VNA	"
label var	Q7_4	"	I was inspired through the state's information about the election	"
label var	Q7_5	"	I am concerned about a particular issue that I want resolved in the VNA	"
label var	Q7_6	"	The government mobilized me to vote	"
label var	Q6_1	"	I don't know about the election	"
label var	Q6_2	"	I didn't have time on the day of the election	"
label var	Q6_3	"	My parents told me that they would vote on my behalf	"
label var	Q6_4	"	I wasn't registered as a voter for the election	"
label var	Q6_5	"	I didn't want to vote	"
label var	Q11_1	"	I do not have a specific reason, and just choose at random	"
label var	Q11_2	"	His/her name was on top of the list	"
label var	Q11_3	"	My parents/relative/friends instructed me to vote for the candidates	"
label var	Q11_4	"	The voting staff instructed me to vote for the candidates	"
label var	Q11_5	"	I know of him/her personally	"
label var	Q11_6	"	I believe he/she will bring personal benefits to me or my immediate family	"
label var	Q11_7	"	I believe he/she will bring about positive changes for myself, my commmunity, and my country	"
label var	Q11_8	"	I believe the candidates would represent the voice, concerns, and interest of mine at the VNA	"
label var	Q11_9	"	His/her professional qualifications (education, experience) appealed to me	"
label var	Q11_10	"	His/her gender appealed to me (male or female)	"
label var	Q11_11	"	His/her age (young or senior)	"
label var	Q11_12	"	His/her race (Kinh or other ethnicities)	"
label var	Q11_13	"	His/her affiliation with a certain agency (Women Union, Youth Union, Communist Party, etc)	"
label var	Q11_14	"	His/her ability to represent me (Ex: the staff currently working at a locality)	"
label var	Q11_15	"	I want to create opportunities for candidates that don't have advantages	"
label var	Q10_1	"	The voting poll is close to my house, which is convenient for me and my family	"
label var	Q10_2	"	The voting day is on Sunday, which is convenient for me and my family	"
label var	Q10_3	"	The election officials are supportive and helpful	"
label var	Q10_4	"	The election information displayed at the polls are comprehensive and insightful	"
label var	Q12_1	"	A voter voting on behalf of many voters (families, friends, etc)	"
label var	Q12_2	"	The principle of 'secret vote' is not respected (no one is allowed to look at your ballot)	"
label var	Q12_3	"	The staff instructs voters to vote for particular candidates	"
label var	Q12_4	"	The staff refuses to provide a new ballot when sb's is broken	"
label var	Q12_5	"	No negative phenomenon	"

*Q2 Q3 Q4
encode Q2, gen (Q2_en)
label define Q2_en 1 "I intend to keep updated on the VNA through the news/highlights on TV" 2"I intend to watch the debates on television/social media platforms" 3 "I do not intend to and I do not have interest in keeping update with the VNA debates", replace
label var Q2_en "After the election, do you plan to watch/observe news on the upcoming VNA meetings?"
label var Q4 "On 0-10, how confident are you that the newly elected VNA will be responsive to your personal policy objectives or those of your community ?"
label var	Q3_1	"	Meeting sessions at the general assembly"
label var	Q3_2	"	Minister hearings sessions"
label var	Q3_3	"	Voting sessions on draft laws"
label var	Q3_4	"	Discussion in specialized/select committees"
label var	Q3_5	"	Vote of confidence for cabinet members"
label var	Q3_6	"	I don't plan on watching/observing"

*Q14 Q16 Q18
label var	Q14_1	"	State organizations	"
label var	Q14_2	"	Youth Communist Union	"
label var	Q14_3	"	University	"
label var	Q14_4	"	News organization	"
label var	Q14_5	"	KOL	"
label var	Q14_6	"	Nothing at all	"
label var	Q16_1	"	Mainstream online news website	"
label var	Q16_2	"	State's online resources	"
label var	Q16_3	"	State's sms messages	"
label var	Q16_4	"	Offline newspaper	"
label var	Q16_5	"	Television	"
label var	Q16_6	"	Social media	"
label var	Q16_7	"	Leaflet	"
label var	Q16_8	"	Banners	"
label var	Q16_9	"	Public speakers	"
label var	Q18_1	"	Infographic	"
label var	Q18_2	"	General news	"
label var	Q18_3	"	Interview with prominent speakers	"
label var	Q18_4	"	Creative videos	"
label var	Q18_5	"	Traditional photos (with socilalist propaganda themes from the state)	"
label var	Q18_6	"	Creative photos	"
label var	Q18_7	"	Online events (hashtag trandes, facebaook avatar campaigns, etc)	"


*Q13
encode Q13, gen (Q13_en)
label define Q13_en 1"I do not remember" 2"I did not do any thing related to election prior to voting" 3"I did not do research, but received information from other people about the Election prior to voting" 4 "I did some research on Election and Candidate information prior to voting" 5 "I did a lot of research on Election and Candidate information prior to voting",replace
label var Q13_en "Please select your behavior from the time up to Election date?"

*Q15
encode Q15, gen (Q15_en)
label define Q15_en 1 "News organization" 3 "Nothing at all" 4"Key opinion leaders/celebrity (KOL)" 6"University" 7"State organization" 10 "Youth Communist Union",replace
label var Q15_en "Out of the selected media sources in Q14, which one do you most prefer to see election information? (Select only one)"

*Q17
encode Q17, gen (Q17_en)
label define Q17_en 1 "Banners" 2"Offline newspaper" 3"Mainstream online news website" 4"State's online resources" 7"Public speakers" 8"Social media" 10 "State's SMS messages" 11 "Television" 12 "Leaflet", replace
label var Q17_en "Through which media channels in Q16 that you have seen election information?"

*Q19
encode Q19, gen (Q19_en)
label define Q19_en 1"Creative video" 2 "Creative photos" 3"Traditional photos (with socilalist propaganda themes from the state)" 4"Infographic" 6"Interview with prominent speakers" 7 "Online events (hashtag trandes, facebaook avatar campaigns, etc)" 8 "General news", replace
label var Q19_en "What kind of information modes in Q18 did you prefer the most to see on the selected channels? (Select only one)"

*Q20
encode Q20, gen (Q20_en)
label define Q20_en 3 "National Assembly's achievements, duties, roles, etc" 4"Information about legislation to be considered by the VNA " 5"Information about specific candidates" 6"Voting procedures, election laws, logistic information",replace
label var Q20_en "Which information/content did you see the most through the selected channels/sources above?"

*Q21
encode Q21, gen (Q21_en)
label define Q21_en 1 "Both email and physical" 2"Via physical" 3"Via email" 4"I did not receieve anything",replace
label var Q21_en "CRUS sent you some information package prior to the Election. You received:"

*Q24
encode Q24, gen (Q24_en)
label define Q24_en 1 "T1: Civic Duty" 2"T3: Legislative agenda" 3"T2: Candidate quality",replace
label var Q24_en "Q24. What was the information you recieved about?"

*Q26
encode Q26, gen (Q26_en)
label define Q26_en 1 "T1: Civic Duty" 2"T3: Legislative agenda" 3"T2: Candidate quality",replace
label var Q26_en "Q26. What was the information you recieved about?"

drop treatment_group
generate treatment_group=0 if control==1
replace treatment_group=1 if T1==1
replace treatment_group=2 if T2==1
replace treatment_group=3 if T3==1
lab var treatment_group "Treatment Group"
label define group 0 "Control" 1 "T1: Civic Duty" 2 "T2: Candidate Quality"  3 "T3: Policy Objectives",replace
label val treatment_group group
tab treatment_group

drop age male motorbikes
generate age=2021-birthyear
generate male=1 if gender=="Nam"
replace male=0 if male==.
generate motorbikes=0 if motorbike_own=="Không sở hữu"
replace motorbikes=1 if motorbike_own=="1 chiếc"
replace motorbikes=2 if motorbike_own=="2 chiếc"
replace motorbikes=3 if motorbike_own=="Nhiều hơn 2 chiếc"


*Exposure variable define

gen receive=1
replace receive=0 if p2_physicaldelivery=="Failed"
replace receive=0 if p2_Qrdelivery==0
replace receive=. if P3=="No"
label define map_check 1"True" 0"False",replace
label val receive  map_check
label var receive "Received info pack"

gen correctrecall=0
replace correctrecall=1 if treatment_group==1 & Q24_en==1
replace correctrecall=1 if treatment_group==1 & Q26_en==1
replace correctrecall=1 if treatment_group==2 & Q24_en==3
replace correctrecall=1 if treatment_group==2 & Q26_en==3
replace correctrecall=1 if treatment_group==3 & Q24_en==2
replace correctrecall=1 if treatment_group==3 & Q26_en==2
label define map_check 1"True" 0"False",replace
label val correctrecall map_check
label var correctrecall "Correctly recalled info pack content"

gen aware=0
replace aware=1 if Q21_en!=4
label val aware map_check
label var aware "Aware of having received info pack"

*Outcome variables
*outcome 1

gen Vote=0
replace Vote=1 if Q5_en ==3|Q5_en==2
replace Vote=0 if Q5_en==1
replace Vote=. if Q5_en==.
label var Vote "Voted in last election"
label define YesNo  1 "Yes" 0 "No", replace
label val Vote YesNo

generate vote_directly=1 if Q5_en==3
replace vote_directly=0 if Q5_en==1|Q5_en==2
label var vote_directly "Voted directly (No Proxy)"
label val vote_directly YesNo

*outcome 2
*Name recall
gen	nameNAHCM	=real(Q8b_name_NA_HCM)
gen	namePCHCM	=real(Q8b_name_PC_HCM)
gen	nameNAorigin	=real(Q8b_name_NA_origin)
gen	namePCorigin	=real(Q8b_name_PC_origin)
gen	nameNAothers	=real(Q8b_name_NA_others)
gen	namePCothers	=real(Q8b_name_PC_others)

gen nameNA=max(nameNAHCM, nameNAorigin)
gen namePC=max(namePCHCM, namePCorigin)
label var nameNA "Number of names recalled in NA"
label var namePC "Number of names recalled in PC"

*Position recall
gen	posNAHCM	=real(Q9b_pos_NA_HCM)
gen	posPCHCM	=real(Q9b_pos_PC_HCM)
gen	posNAorigin	=real(Q9b_pos_NA_origin)
gen	posPCorigin	=real(Q9b_pos_PC_origin)
gen	posNAothers	=real(Q9b_pos_NA_others)
gen	posPCothers	=real(Q9b_pos_PC_others)

gen posNA=max(posNAHCM, posNAorigin)
gen posPC=max(posPCHCM, posPCorigin)
label var posNA "Number of positions recalled in NA"
label var posPC "Number of positions recalled in PC"

*outcome 3
gen CorrectVoteReason=0
replace CorrectVoteReason=1 if Q11_7=="1"
replace CorrectVoteReason=1 if Q11_8=="1"
replace CorrectVoteReason=. if P3=="No"
label var CorrectVoteReason "Correct voting reason according to PAP"

gen Correct3VoteReason=0
replace Correct3VoteReason=1 if Q11_7=="1"
replace Correct3VoteReason=1 if Q11_8=="1"
replace Correct3VoteReason=1 if Q11_14=="1"
replace Correct3VoteReason=. if P3=="No"
label var Correct3VoteReason "Correct voting reasons with 3 options"

gen RationalVoteReason=0
replace RationalVoteReason=1 if Q11_6=="1"
replace RationalVoteReason=1 if Q11_7=="1"
replace RationalVoteReason=1 if Q11_8=="1"
replace RationalVoteReason=1 if Q11_9=="1"
replace RationalVoteReason=1 if Q11_10=="1"
replace RationalVoteReason=1 if Q11_11=="1"
replace RationalVoteReason=1 if Q11_12=="1"
replace RationalVoteReason=1 if Q11_13=="1"
replace RationalVoteReason=1 if Q11_14=="1"
replace RationalVoteReason=1 if Q11_15=="1"
replace RationalVoteReason=. if P3=="No"
label var RationalVoteReason "Rational voting reasons"

*outcome 4
*all data (non vote/vote indirectly w/o data is coded as 0)
gen VNALegitimacy_all=0
replace VNALegitimacy_all=0 if Q2_en==3
replace VNALegitimacy_all=1 if Q2_en<=2
replace VNALegitimacy_all=. if P3=="No"
label var VNALegitimacy_all "Intention to watch VNA meeting - all data"
label val VNALegitimacy_all YesNo

gen VNALegitimacy_high=0
replace VNALegitimacy_high=0 if Q2_en==3
replace VNALegitimacy_high=1 if Q2_en==2
replace VNALegitimacy_high=2 if Q2_en==1
replace VNALegitimacy_high=. if P3=="No"
label var VNALegitimacy_high "Level of VNA Engagment"
label define scale  2 "Watch TV" 1 "Social Media" 0 "No Watch", replace
label val VNALegitimacy_high scale


*outcome 5
*all data (non vote/vote indirectly w/o data is coded as 0)
gen VNAConfidence_all=real(Q4)
replace VNAConfidence_all=0 if VNAConfidence_all==.
replace VNAConfidence_all=. if P3=="No"
label var VNAConfidence_all "Confidence score for NA - all data"



*Information exposure level
destring Q16_*, replace
egen Noofexposure = rowtotal(Q16_*)
label var Noofexposure "Number of channels exposed to"
replace Noofexposure=1 if Noofexposure==0



*actual voting location
gen ActualVoteLocation=0
replace ActualVoteLocation=1 if nameNAHCM~=0 | namePCHCM~=0
replace ActualVoteLocation=. if P3=="No"
label define ActualVoteLocation 1 "HCM" 0 "Elsewhere"
label val ActualVoteLocation ActualVoteLocation
label var ActualVoteLocation "Actual Vote Location"


*Creating variables for total number of recall
egen Name=rowtotal(nameNA namePC)
label var Name "No. of names recalled"
egen Position=rowtotal (posNA posPC)
label var Position "No. of positions recalled"

label var T1 "T1: Civic Duty"
label var T2 "T2: Candidate Quality"
label var T3 "T3: Policy Objectives"


gen research=0 
replace research=1 if Q13_en==4
replace research=1 if Q13_en==5
replace research=. if P3=="No"
label val research polibg2
label var research "Research behavior for Election"



generate vote_proxy=1-vote_directly if Vote==1
replace vote_proxy=0 if Vote==0
replace electiondateawareness_rc  = electiondateawareness_rc-1
gen Q5_code=0 if Vote==0
replace Q5_code=1 if vote_proxy==1
replace Q5_code=2 if vote_directly==1
generate Q5_code2=(3-Q5_code) if Q5_code!=0
replace Q5_code2=0 if Q5_code==0


foreach x in Q11_1 Q11_2 Q11_3 Q11_4 Q11_5 Q11_6 Q11_7 Q11_8 Q11_9 Q11_10 Q11_11 Q11_12 Q11_13 Q11_14 Q11_15 {
    destring `x', replace
	label val `x' YesNo
	replace `x'=`x'*100
}

#delimit;
graph hbar Q11* if treatment_group==0, legend(pos(9) size(medium) label(1 No Reason) label(2 Name topped list) label(3 Relative/friend instructed) label(4 Voting staff instructed) label(5 Personally know candidate) label(6 Personalistic benefits) label(7 Positive change for community) label(8 Represent citizens' interests) label(9 Professional qualifications) label(10 Candidate's gender) label(11 Candidate's age) label(12 Candidate's race) label(13 Candidate's mass organization) label(14 Local knowledge) label(15 Vote for disadvantaged group)) blabel(bar, size(small) position(Inside) format(%3.1f)) ylab(0(2)28, labsize(small)) ytitle("Main reason for vote choice (%)", size(medium) margin(medsmall));

graph bar (mean) Q11_7, over(treatment_group)  blabel(bar, size(medium) position(Inside) format(%3.2f));

#delimit cr
foreach x in Q11_1 Q11_2 Q11_3 Q11_4 Q11_5 Q11_6 Q11_7 Q11_8 Q11_9 Q11_10 Q11_11 Q11_12 Q11_13 Q11_14 Q11_15 {
	replace `x'=`x'/100
}

save "election_working.dta", replace

